<template>
    <div class="tree-menu">
        <Button type="error" size="large" @click="jumpPage('','GroupGroupAdd')" style="margin-bottom: 20px">新增功能分组
        </Button>
        <cTree :data="data" :father="this"></cTree>
        <!--<button @click="$store.commit('add')">+</button>-->
        <!--<button @click="$store.commit('reduce')">-</button>-->
    </div>
</template>

<script>

    import apiUtil from '../../assets/utils/api_util';
    import cTree from '../../components/treesGroup';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                data: '',
            }
        },
        components: {
            cTree
        },
        created() {
            this.getGroupData();
        },
        methods: {
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            getStructuresData(group) {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.ListStructures, para, function (res) {
                    that.$Loading.finish();
                    let newStrArr = [];
                    res.Msg.forEach(function (item, i) {
                        let itemObj = {};
                        itemObj.GroupName = item.Interfaceurl + ' ' + '(' + item.Description + ')';
                        itemObj.Id = item.Id;
                        itemObj.Groupid = item.Groupid;
                        itemObj.SubGroups = [];
                        newStrArr.push(itemObj);
                    });
                    group.forEach(function (itemSub, j) {
                        newStrArr.forEach(function (item, i) {
                            if (item.Groupid == itemSub.Id) {
                                itemSub.SubGroups.push(item);
                            }
                        });
                    })
                });
            },
            getGroupData: function () {
                let that = this;

                let para = {};

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.ListStructureGroup, para, function (res) {
                    that.data = res.Msg;
                    that.getStructuresData(res.Msg);
                });

            }
        }
    }
</script>
